{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a0ed198-6f5e-45dc-8a32-9273640dd563",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Setup OpenAI Agent\n",
    "import openai\n",
    "\n",
    "openai.api_key = \"sk-xxx\"\n",
    "from llama_index.agent.openai import OpenAIAgent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96f222e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "447e016d",
   "metadata": {},
   "outputs": [],
   "source": [
    "agent = OpenAIAgent.from_tools(\n",
    "    DuckDuckGoSearchToolSpec().to_tool_list(),\n",
    "    verbose=True,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "943e749c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Added user message to memory: Who is Goethe?\n",
      "=== Calling Function ===\n",
      "Calling function: duckduckgo_instant_search with args: {\"query\":\"Goethe\"}\n",
      "Got output: [{'icon': None, 'text': 'Johann Wolfgang Goethe was a German polymath and writer, who is widely regarded as the greatest and most influential writer in the German language. His work has had a profound and wide-ranging influence on Western literary, political, and philosophical thought from the late 18th century to the present day. Goethe was a German poet, playwright, novelist, scientist, statesman, theatre director, and critic. His works include plays, poetry, literature, and aesthetic criticism, as well as treatises on botany, anatomy, and color. Goethe took up residence in Weimar in November 1775 following the success of his first novel, The Sorrows of Young Werther. He was ennobled by the Duke of Saxe-Weimar, Karl August, in 1782. Goethe was an early participant in the Sturm und Drang literary movement.', 'topic': None, 'url': 'https://en.wikipedia.org/wiki/Johann_Wolfgang_von_Goethe'}, {'icon': 'https://duckduckgo.com/i/edd6fba6.jpg', 'text': 'Johann Wolfgang von Goethe A German poet, playwright, novelist, scientist, statesman, theatre director, and critic.', 'topic': None, 'url': 'https://duckduckgo.com/Johann_Wolfgang_von_Goethe'}, {'icon': 'https://duckduckgo.com/i/c819f955.png', 'text': 'Goethe University Frankfurt A university located in Frankfurt am Main, Germany.', 'topic': None, 'url': 'https://duckduckgo.com/Goethe_University_Frankfurt'}, {'icon': 'https://duckduckgo.com/i/www.goethe.de.ico', 'text': 'Goethe-Institut A non-profit German cultural association operational worldwide with 159 institutes, promoting the...', 'topic': None, 'url': 'https://duckduckgo.com/Goethe-Institut'}, {'icon': None, 'text': \"Goethe (grape) Goethe is one of the collection of grape varieties known as Rogers' Hybrids, created by E.S.\", 'topic': None, 'url': 'https://duckduckgo.com/Goethe_(grape)'}, {'icon': 'https://duckduckgo.com/i/6eff7e53.jpg', 'text': 'Goethe (train) An express train that, for most of its existence, linked Paris-Est in Paris, France, with...', 'topic': None, 'url': 'https://duckduckgo.com/Goethe_(train)'}, {'icon': 'https://duckduckgo.com/i/71aac73b.gif', 'text': '3047 Goethe A bright background asteroid from the central regions of the asteroid belt, approximately in...', 'topic': None, 'url': 'https://duckduckgo.com/3047_Goethe'}, {'icon': 'https://duckduckgo.com/i/c71989d7.jpg', 'text': 'Goethe! A 2010 German historical drama film directed by Philipp Stölzl and starring Alexander Fehling...', 'topic': None, 'url': 'https://duckduckgo.com/Young_Goethe_in_Love'}, {'icon': None, 'text': 'Mount Goethe A summit in Fresno County, California, in the United States.', 'topic': None, 'url': 'https://duckduckgo.com/Mount_Goethe'}, {'icon': None, 'text': 'Goethe Awards An American series of comic book fan awards, first presented in 1971 for comics published in 1970.', 'topic': 'See also', 'url': 'https://duckduckgo.com/Goethe_Awards'}, {'icon': 'https://duckduckgo.com/i/b41b9fb4.jpg', 'text': 'Goethe Prize An award for achievement \"worthy of honour in memory of Johann Wolfgang von Goethe\" made by the...', 'topic': 'See also', 'url': 'https://duckduckgo.com/Goethe_Prize'}, {'icon': None, 'text': 'Goethe Medal A yearly prize given by the Goethe-Institut honoring non-Germans \"who have performed outstanding...', 'topic': 'See also', 'url': 'https://duckduckgo.com/Goethe_Medal'}, {'icon': None, 'text': 'Goethe Basin An impact basin at 81.4° N, 54.3° W on Mercury approximately 317 kilometers in diameter.', 'topic': 'See also', 'url': 'https://duckduckgo.com/Goethe_Basin'}, {'icon': None, 'text': \"Goethe (surname) See related meanings for the phrase 'Goethe (surname)'.\", 'topic': 'See also', 'url': 'https://duckduckgo.com/d/Goethe_(surname)'}, {'icon': None, 'text': \"Gote See related meanings for the word 'Gote'.\", 'topic': 'See also', 'url': 'https://duckduckgo.com/d/Gote'}]\n",
      "========================\n",
      "\n",
      "Johann Wolfgang Goethe was a German polymath and writer, widely regarded as the greatest and most influential writer in the German language. He was a poet, playwright, novelist, scientist, statesman, theatre director, and critic. Goethe's work has had a profound influence on Western literary, political, and philosophical thought. He took up residence in Weimar in 1775 and was ennobled by the Duke of Saxe-Weimar in 1782. For more information, you can visit the [Wikipedia page](https://en.wikipedia.org/wiki/Johann_Wolfgang_von_Goethe).\n"
     ]
    }
   ],
   "source": [
    "agent.chat_history.clear()\n",
    "print(agent.chat(\"Who is Goethe?\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d46804f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Added user message to memory: Give me a quote of Goethe (Deutsch)?\n",
      "=== Calling Function ===\n",
      "Calling function: duckduckgo_full_search with args: {\"query\":\"Goethe Zitat\",\"region\":\"de\",\"max_results\":1}\n",
      "Got output: [{'title': 'Johann Wolfgang von Goethe Quotations - ThoughtCo', 'href': 'https://www.thoughtco.com/goethe-zitate-german-english-quotations-4069390', 'body': 'Sie rauben euch beides, Zeit und Stimmung.\" English Translation: Of all the thieving riff-raff, fools are the worst. They steal both your time and your good mood. \"Das Leben gehört den Lebenden an, und wer lebt, muss auf Wechsel gefasst sein.\"'}]\n",
      "========================\n",
      "\n",
      "Here is a quote by Johann Wolfgang von Goethe in German:\n",
      "\n",
      "\"Sie rauben euch beides, Zeit und Stimmung.\"\n",
      "English Translation: \"Of all the thieving riff-raff, fools are the worst. They steal both your time and your good mood.\"\n",
      "\n",
      "If you would like more quotes or information about Goethe, you can visit the [source](https://www.thoughtco.com/goethe-zitate-german-english-quotations-4069390).\n"
     ]
    }
   ],
   "source": [
    "print(agent.chat(\"Give me a quote of Goethe (Deutsch)?\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
